package com.kdtech.analyse.video;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.kdtech.crawler.CrawlHTML;
import com.kdtech.entity.crawler.UrlMeta;
import com.kdtech.entity.data.NewsMeta;
import com.kdtech.utils.DateUtils;
import com.kdtech.utils.NumberUtils;
import com.kdtech.utils.StringUtils;
import com.kdtech.analyse.AnalyseNews;

/**
 *  上饶电视台 解析类
 * 
 * @author Chase
 * 
 */
public class _0793VideoAnalyse implements AnalyseNews {



	
	public boolean isDetailPage(String url) {
		boolean bRet = false;
//		if(url.indexOf("zjxc") != -1 || url.indexOf("spzt") != -1 || url.indexOf("qwts") != -1) {
//			return bRet;
//		}
		if(url.indexOf("/xwlb/")!=-1) return false;
		String[] regex = {
				"http://n.0793.tv/.*/[0-9]+/[0-9]+/[0-9]+.shtml"
				};
		for (int i = 0; i < regex.length; i++) {
			if (url.matches(regex[i])) {
				return true;
			}
		}
		return bRet;
	}	

	
	public NewsMeta parserHtml(UrlMeta urlMeta) {

		String url = urlMeta.getUrl(); 
		/**
		 * 判断是否为详细页，不是详细页面直接返回空
		 */
		if (!isDetailPage(url)) {
			System.err.println("不符合规则");
		}

		String html = urlMeta.getHtml();

		/*
		 * 定义新闻实体需要的字段
		 */
		String title = null;
		String dateStr = null;
		String desc = null;
		Long dateLong = null;
		String commentNum = null;
		String clickNum = null;
		String substringBetween = StringUtils.substringBetween(html, "var videos = [{", "}];");
		if(StringUtils.isNotBlank(substringBetween)){
			title = StringUtils.substringBetween(substringBetween, "title:'", "'");
			desc = StringUtils.substringBetween(substringBetween, "desc:'", "'");
			NewsMeta meta = new NewsMeta();
			meta.setTitle(title);
			meta.setContent(desc);
			meta.setUrl(url);
			meta.setType(2);
			dateLong = DateUtils.matchDate(url);
			meta.setDate(dateLong);
			
			return meta;
		}
		return null;
		
	}
	
	
	public NewsMeta Update(NewsMeta meta) {
		return null;
	}


	
}
